class Parser:
    '''
    This is the class all other parser should inherit from.
    '''
    
    tags = ()            
            
    def _updateTagsList(self, text):
        '''
        Stores the start end the end of all tags into tagsList.
        '''
        
        self.tagsList = []
        
        starttags = [a for a, b in self.tags]
        endtags = [b for a, b in self.tags]
        end=0
        while True:
            #find first tag:
            tag = None
            pos = len(text)
            for i in starttags:
                t = text.find(i, end)
                if t!=-1 and t<pos:
                    tag = i
                    pos = t
            if not tag:
                break
            
            #find closing tag:
            endtag = endtags[starttags.index(tag)]
            end = text.find(endtag, pos)
            if end==-1:
                self.tagsList.append((pos, len(text)-1))
                break
            self.tagsList.append((pos, end+len(endtag)-1))
                
    def _insideTag(self, pos):
        '''
        Returns True if pos is inside a tag defined in tagsList.
        '''
        
        for start, end in self.tagsList:
            if start<=pos<=end:
                return True
        return False